<?php
  /**
   * Send email
   * @author Trong Hieu
   * @param string $to Destination
   * @param string $subject Subject
   * @param string $content Content
   * @param array $froms Sources
   * @param array $tos Supplements destinations
   * @param array $ccs CCs
   * @param array $bccs BCCs
   * @param bool $html Is email HTML ?
   */
  function sendMail($to, $from, $subject, $content, $replyTos = array(), $tos = array(), $ccs = array(), $bccs = array(),  $html = false) {
    $header = '';
    if ($html) {
      $header .= 'MIME-Version: 1.0'."\r\n";
      $header .= 'Content-type: text/html; charset=utf-8'."\r\n";
    }
    
    $header .= 'From: '.$from."\r\n";
    $header .= !empty($tos) ? 'To: '.implode(',', $tos)."\r\n" : '';
    $header .= !empty($ccs) ? 'CC: '.implode(',', $ccs)."\r\n" : '';
    $header .= !empty($bccs) ? 'BCC: '.implode(',', $bccs)."\r\n" : '';
    $header .= !empty($replyTos) ? 'Reply-To: '.implode(',', $replyTos)."\r\n" : '';

    if (!mail($to, $subject, $content, $header)) throw new Exception('File : '.__FILE__.'<br />Line : '.__LINE__."<br />Error : Unable to send email with this function: <b>mail(".$to.", ".$subject.", ".$content.", ".$header.")</b>");
    
    return true;
  }
?>
